//var urlcore = "http://192.168.1.100:8081";
 
var urlcore = "http://www.jiagangwangluo.com/jgsc";
 
var pageSize = 8;
//从url中获取参数值
function getvl(name) {
    var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
    if (reg.test(location.href.trim())) return unescape(RegExp.$2.replace(/\+/g, " "));
    return "";
};
//从url中获取参数值(解码汉字)
function getvl1(name) {
    var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
    if (reg.test(location.href.trim())) return decodeURI(RegExp.$2.replace(/\+/g, " "));
    return "";
};


//设置全局ajax
$.ajaxSetup({
    xhrFields: {
    	withCredentials: true
	}
});


$(function() {
	//时间格式化
	Date.prototype.pattern=function(fmt) {
	    var o = {
	    "M+" : this.getMonth()+1, //月份         
	    "d+" : this.getDate(), //日         
	    "h+" : this.getHours(), //小时         
	    "H+" : this.getHours(), //小时         
	    "m+" : this.getMinutes(), //分         
	    "s+" : this.getSeconds(), //秒         
	    "q+" : Math.floor((this.getMonth()+3)/3), //季度         
	    "S" : this.getMilliseconds() //毫秒         
	    };         
	    var week = {         
	    "0" : "/u65e5",         
	    "1" : "/u4e00",         
	    "2" : "/u4e8c",         
	    "3" : "/u4e09",         
	    "4" : "/u56db",         
	    "5" : "/u4e94",         
	    "6" : "/u516d"        
	    };         
	    if(/(y+)/.test(fmt)){         
	        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));         
	    }         
	    if(/(E+)/.test(fmt)){         
	        fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "/u661f/u671f" : "/u5468") : "")+week[this.getDay()+""]);         
	    }         
	    for(var k in o){         
	        if(new RegExp("("+ k +")").test(fmt)){         
	            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));         
	        }         
	    }         
	    return fmt;         
	}
});

function typeToServerName(type){
	if(type==1){
		return "摄影师";
	}
	if(type==2){
		return "租车";
	}
	if(type==3){
		return "导游";
	}
	if(type==4){
		return "模特";
	}
	if(type==5){
		return "化妆师";
	}

}

function typeToPayName(type){
	if(type==1){
		return "余额支付";
	}
	if(type==2){
		return "支付宝支付";
	}
	if(type==3){
		return "微信支付";
	}
	if(type==''||type==null){
		return "";
	}
}

 //初始化fileinput控件（第一次初始化）
function initFileInput(ctrlName, uploadUrl,okName,maxnNum) {    
    var control = $('#' + ctrlName); 
    control.fileinput({
        language: 'zh', //设置语言
        uploadUrl: uploadUrl, //上传的地址
        //uploadExtraData:{"id": 1, "fileName":'123.mp3'},
        resizeImage: true,
        resizePreference: 'width',
        resizeImageQuality: 0.2,
        uploadAsync: true, //默认异步上传
        showUpload: true, //是否显示上传按钮
        showRemove : true, //显示移除按钮
        showPreview : true, //是否显示预览
        showCaption: false,//是否显示标题
        browseClass: "btn btn-primary", //按钮样式     
        dropZoneEnabled: true,//是否显示拖拽区域
        maxFileCount: 10, //表示允许同时上传的最大文件个数
        dropZoneTitle: '拖拽文件到这里 &hellip;',
        enctype: 'multipart/form-data',
        validateInitialCount:true,
        previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
    }).on("fileuploaded", function(event, data,key) {
        if(data.response){	
        	var okData = data.response.data;
        	for (var i = 0; i < okData.length; i++) {
        		var strHtml = 
		            	'<div style="position:relative;width:250px;height:250px;float:left;display:none" id="'+key+'">'+
		            	'	<span onclick="removeStrHtml()" style="position:absolute;top:10px;right:10px;font-size:20px;color:#f00;" class="glyphicon glyphicon-trash" aria-hidden="true">'+
		            	'	</span>'+
		            	'	<img style="padding: 5px 5px 5px 5px;" width="250px" height="250px" src="'+okData[i]+'">'+
		        		'</div>';
		        $(okName).append(strHtml);
        	}
        }
    }).on('filesuccessremove', function(event, key) { 
    	$("#"+key).remove();  
	});
}
   
   
//初始化fileinput控件（第一次初始化）
function initFileInput2(ctrlName, uploadUrl,okName, type) {    
    var control = $('#' + ctrlName); 

    control.fileinput({
    	jsFile: 'shows_admin/js/core.js', //当前js文件目录
        language: 'zh', //设置语言
        uploadUrl: uploadUrl, //上传的地址
        uploadExtraData:{"type": type},
        uploadAsync: true, //默认异步上传
        showUpload: true, //是否显示上传按钮
        showRemove : true, //显示移除按钮
        showPreview : true, //是否显示预览
        showCaption: false,//是否显示标题
        browseClass: "btn btn-primary", //按钮样式     
        dropZoneEnabled: true,//是否显示拖拽区域
        maxFileCount: 10, //表示允许同时上传的最大文件个数
        maxImageWidth: 1000,
        maxImageHeight: null,
        resizeImage: true,
        resizePreference: 'width',        
        dropZoneTitle: '拖拽文件到这里 &hellip;',
        enctype: 'multipart/form-data',
        validateInitialCount:true,
        previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
    }).on("fileuploaded", function(event, data,key) {
        if(data.response){

        	
        	var okData = data.response.data+"***";  
        	 $(okName).append(okData);
        	
        }
    }).on('filesuccessremove', function(event, key) { 
    	var attId = document.getElementById(key).getElementsByTagName('div')[1].getElementsByTagName('button')[1].id;
    	deleteAttachmentOne(attId,okName);
	});
}

   
   
 //初始化fileinput控件（第一次初始化）
function initVideoInput(ctrlName, uploadUrl,okName,maxnNum) {    
    var control = $('#' + ctrlName); 

    control.fileinput({
        language: 'zh', //设置语言
        uploadUrl: uploadUrl, //上传的地址
        //uploadExtraData:{"id": 1, "fileName":'123.mp3'},
        uploadAsync: true, //默认异步上传
        showUpload: true, //是否显示上传按钮
        showRemove : true, //显示移除按钮
        showPreview : true, //是否显示预览
        showCaption: false,//是否显示标题
        browseClass: "btn btn-primary", //按钮样式     
        dropZoneEnabled: true,//是否显示拖拽区域
        maxFileCount: 10, //表示允许同时上传的最大文件个数
        dropZoneTitle: '拖拽文件到这里 &hellip;',
        enctype: 'multipart/form-data',
        validateInitialCount:true,
        previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
    }).on("fileuploaded", function(event, data,key) {
        if(data.response){	
        	var okData = data.response.data;
        	for (var i = 0; i < okData.length; i++) {
        		var strHtml = 
		            	'<div style="position:relative;width:250px;height:250px;float:left;display:none" id="'+key+'">'+
		            	'	<span onclick="removeStrHtml()" style="position:absolute;top:10px;right:10px;font-size:20px;color:#f00;" class="glyphicon glyphicon-trash" aria-hidden="true">'+
		            	'	</span>'+
		            	'	<video id="vd" width="150" height="150" controls="controls" src="'+okData[i]+'">'+
						'	</video>'+
		        		'</div>';
		        $(okName).append(strHtml);
        	}
        }
    }).on('filesuccessremove', function(event, key) { 
    	$("#"+key).remove();  
	});
}

/**
 * 移除Html代码
 */
function removeStrHtml(obj){
	$(obj).parent().remove();
}



//创建
var gc = gc || {};
gc.ajax = function(options){//options =  {url:'',method:'',data:'',callback:'',async:''}
    //默认参数
    options.url = options.url || '',
    options.method = options.method || 'get',
    options.data = options.data || '',
    options.callback = options.callback || '',
    options.async = options.async || true;
    //get请求-拼接url
    if(options.method.toLowerCase() == 'get'){
        if(typeof options.data == 'object'){
            options.data = [];
            for (var k in options.data){
                options.data.push(k+'='+options.data[k]);
                options.data.join('&');
            }
        }
        options.url += (options.url.indexOf('?' == -1) ? '?' : '') + options.data;
    }
    //post请求-转换字符串
    if(options.method.toLowerCase() == 'post'){
        if(typeof options.data == 'object'){
            var arrs = [];
            for (var k in options.data){
                arrs.push(k+'='+options.data[k]);
            }
            options.data = arrs.join('&');
        }
    }
    //创建发送请求
    var xhr = window.XMLHttpRequest ?  new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); //兼容ie
    xhr.open(options.method,options.url,options.async);
    if(options.method == 'post'){
        xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xhr.send(options.data);
    }else{
        xhr.send(null);
    }
    //异步请求
    if(options.async == true){
        xhr.onreadystatechange = function(){
          if(xhr.readyState == 4){
              callcall();
          }
        }
    }
    // xhr.abort(); // 取消异步请求
    //同步请求
    if(options.async == false){
        callcall();
    }
    //返回状态判断
    function callcall(){
        if(xhr.status == 200){
            options.callback(xhr.responseText);
        }else{
            options.callback('error:' + xhr.status + xhr.statusText);
        }
    }
};

//删除数组元素
function removeByValue(arr, val) {
  for(var i=0; i<arr.length; i++) {
    if(arr[i] == val) {
      arr.splice(i, 1);
      break;
    }
  }
}




